package com.prs.crm.dao.assets.impl;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;

import com.prs.crm.dao.assets.AssetsRegisterDao;
import com.prs.crm.dao.impl.BaseDaoImpl;
import com.prs.crm.domain.assets.AssetsLingYong;
import com.prs.crm.domain.assets.AssetsRegister;
import com.prs.crm.domain.assets.AssetsRevert;
import com.prs.crm.domain.assets.AssetsScrap;

public class AssetsRegisterDaoImpl extends BaseDaoImpl<AssetsRegister> 
					implements AssetsRegisterDao{

	@Override
	public List<AssetsRegister> getAllAssetsRegister() {
		Criteria cri = this.getSession().createCriteria(AssetsRegister.class);
		return cri.list();
	}

	@Override
	public AssetsRegister getAllRegisterById(Integer state) {
		Criteria cri = this.getSession().createCriteria(AssetsRegister.class)
		               .add(Restrictions.eq("id", state));
		return (AssetsRegister) cri.list().get(0);
	}

	@Override
	public AssetsRegister getRegisterByNum(String num) {
		Criteria cri = this.getSession().createCriteria(AssetsRegister.class)
						.add(Restrictions.eq("num", num));
		return (AssetsRegister) cri.list().get(0);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<AssetsRegister> getAssetsRegistersByLingYong(
			AssetsLingYong assetsLingYong) {
		Criteria cri = this.getSession().createCriteria(AssetsRegister.class)
		.add(Restrictions.eq("assetsLingYong", assetsLingYong));
		return cri.list();
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<AssetsRegister> getAssetsRegistersByRevert(
			AssetsRevert assetsRevert) {
		Criteria cri = this.getSession().createCriteria(AssetsRegister.class)
		.add(Restrictions.eq("asssteRevert", assetsRevert));
		return (List<AssetsRegister>) cri.list().get(0);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<AssetsRegister> getAssetsRegistersByScrap(
			AssetsScrap assetsScrap) {
		Criteria cri = this.getSession().createCriteria(AssetsRegister.class)
		.add(Restrictions.eq("assetsScrap", assetsScrap));
		return cri.list();
	}
}
